//寻找重复数
class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        int f = 0, s = 0;
        while (1) {
            s = nums[s];
            f = nums[nums[f]];
            if (s == f)
                break;
        }
        f = 0;
        while (1) {
            s = nums[s];
            f = nums[f];
            if (s == f)
                break;
        }
        return f;
    }
};

//下一个排列
class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        int n = nums.size();
        int i = n - 1;
        while (i >= 1 && nums[i] <= nums[i - 1]) {
            i--;
        }
        if (i >= 1) {
            int j = n - 1;
            while (j >= 1 && nums[j] <= nums[i - 1]) {
                j--;
            }
            swap(nums[i - 1], nums[j]);
        }
        reverse(nums.begin() + i, nums.end());
    }
};